<template>
	<div>
		<header-top></header-top>
		<div class="shelves-content">
			<div class="main-width">
				<!-- 侧边栏 shelves-left -->
				<div class='shelves-left'>
					<el-col>
					    <el-menu :default-active="defaultActive" class="el-menu-vertical-demo"   :default-openeds="defaultOpen" @select="setStatus">
					      <el-submenu index="1">
					        <template slot="title">全部商品</template>
					       <!-- <div slot="title" class='slide-title'>
					       		全部商品
					       </div> -->
					        <el-menu-item index="1-0" :default-active="true">
					        		<template slot="title">全部 （{{kindNumber.all}}）</template>
					        </el-menu-item>
					        <el-menu-item index="1-1">
					        		<template slot="title">未生效 ({{kindNumber.noSend}})</template>
					        </el-menu-item>
					        <el-menu-item index="1-2">
					        		<template slot="title">有更优价格 （{{kindNumber.betterPrice}}）</template>
					        </el-menu-item>
					        <el-menu-item index="1-3">
					        		<template slot="title">货源已涨价 （{{kindNumber.riseFailure}}）</template>
					        </el-menu-item>
					        <el-menu-item index="1-4">
					        		<template slot="title">断货 （{{kindNumber.noInventory}}）</template>
					        </el-menu-item>
					        <el-menu-item index="1-5">
					        		<template slot="title">正常生效 （{{kindNumber.normalSales}}）</template>
					        </el-menu-item>
					        <el-menu-item index="1-6">
					        		<template slot="title">商品回收站 （{{kindNumber.collect}}）</template>
					        </el-menu-item>
					        
					      </el-submenu>
					     
					    </el-menu>
					  </el-col>
				</div>
				<!-- 货架内容  shelves-right -->
				<div class="shelves-right">
					<div class="shelves-right-wrap">
							<!-- 商品货架  start -->
							<div class="goods-shelves" v-show="isShow">
								<div class="shelves-filter-wrap">
									<span class="shelves-input-item">
										<label>SKU：</label>
										<span>
											<input type="text" placeholder="请输入SKU" v-model="condition.productId" />
										</span>
									</span>
									<span class="shelves-input-item">
										<label>品牌名称：</label>
										<span>
											<input type="text" placeholder="请输入品牌名称" v-model="condition.brandName" />
										</span>
									</span>
									<span class="shelves-input-item">
										<label>商品名称：</label>
										<span>
											<input type="text" placeholder="请输入商品名称" v-model="condition.goodsName"/>
										</span>
									</span>
									<span class="shelves-input-item">
										<!-- <label>二级分类：</label>
										<span class="classify-query">
											  <el-select v-model="condition.categoryTwoName" clearable placeholder="请输入货品编号" size="small">
											    <el-option

											      v-for="item in resTwoCatagory"
											      :key="item.value"
											      :label="item.label"
											      :value="item.label">
											    </el-option>
											  </el-select>
										</span> -->
										<label>二级分类：</label>
										<span>
											<input type="text" placeholder="请输入商品名称" v-model="condition.categoryTwoName"/>
										</span>
									</span>
									<span class="shelves-input-item">
										<label>三级分类：</label>
										<span>
											<input type="text" placeholder="请输入商品名称" v-model="condition.categoryThreeName"/>
										</span>
										<!-- <label>三级分类：</label>
										<span class="classify-query">
											 <el-select v-model="condition.categoryThreeName" clearable placeholder="请输入货品编号" size="small">
											    <el-option
											      v-for="item in resThreeCatagory"
											      :key="item.value"
											      :label="item.label"
											      :value="item.label">
											    </el-option>
											  </el-select>
										</span> -->
									</span>
									<span>
										<span class="shelves-filter-btn-default shelves-filter" @click="init">筛选</span>
										<span class="shelves-filter-btn-default shelves-cancel" @click="clearCondition">取消</span>
									</span>
								</div>
								<div class="mar-top-15 operation">
									<!-- 批量推送 -->
									<el-dropdown split-button type="primary" trigger="click" size="small" @click="push" :hide-on-click="false">
									  	批量推送
									  	<el-dropdown-menu slot="dropdown">
									    	<el-dropdown-item>
									    		<el-checkbox v-model="sendUpdateGoods">名称和建议售价</el-checkbox>
									    	</el-dropdown-item>
									    	<el-dropdown-item>
									    		<el-checkbox v-model="sendUpdateGoodsDetail">主图与详情图</el-checkbox>
									    	</el-dropdown-item>
									    	<el-dropdown-item>
									    		<el-checkbox v-model="sendUpdateSalePrice">实际售价</el-checkbox>
									    	</el-dropdown-item>
									  	</el-dropdown-menu>
									</el-dropdown>
									<!-- 批量放入回收站 -->
									<div class="batch-operation" @click="putInbin">
										<span>批量放入回收站</span>
									</div>
									<div class="batch-operation ineffective-operation" style="float:right" @click="pushIneffective">推送所有未生效信息</div>
								</div>
								<div>
									<div class="noData" v-if="isShowImg">
										<img src="../assets/img/erro@2x.png">
										<p>暂未发现任何商品</p>
									</div>
									<table class="shelves-table" v-if="!isShowImg">
										<thead>
											<tr>
												<th class="table-header-selectall" :class="{'yigouxuan': isSelect}" @click="allSelect">全选</th>
												<th>操作</th>
												<th>货品SKU</th>
												<th>建议售价</th>
												<th>结算价 (+运费）</th>
												<th>可供库存</th>
												<th>是否含税</th>
												<th>利润率</th>
												<th>状态</th>
											</tr>
										</thead>

										<tbody v-for="(item, index) in goodsList">
											<tr v-if="index == 0">
												<td colspan="11" class="self-tbody-space"></td>
											</tr>
											<tr>
												<td colspan="11" class="shelves-table-block-title" @click="selectItemAll(index)" :class="{'yigouxuan': selectItem[index].isSelect}">
													<span>
														商品品牌：
														<label>{{item.brandName}}</label>
													</span>
													<span class="shelves-table-block-name dianshang" v-if="item.channel === 2">
														商品名称：{{item.goodsName}}
													</span>
													<span class="shelves-table-block-name mendian" v-else-if="item.channel === 1">
														商品名称：{{item.goodsName}}
													</span>
													<span class="shelves-table-block-name haitao" v-else>
														商品名称：{{item.goodsName}}
													</span>
													
													<span>
														
														<label>{{item.categoryTwoName}} / {{item.categoryThreeName}}</label>
													</span>
												</td>
											</tr>
											<tr class="shelves-table-item hasborder" v-for="(value, index1) in item.shelvesProduct">
												<td class="shelves-table-item-select" @click="selectItemFuc(index, index1)" v-if="selectItem[index].shelvesProduct[index1].isSelect" :class="{'yigouxuan': selectItem[index].shelvesProduct[index1].isChecked}"></td>
												<td class="shelves-table-item-default" v-else></td>
												<td>
													<div>
														<div class="td-div-marBot" v-if="value.activity.length != 0">
															<div v-if="value.activity[0].activityJoinStatus == 0">
																<div class="activity-btn" v-if="value.shelvesVo.length == 2&&value.shelvesVo[1].lineStatus != 5" @click="activityOption(1,value.activity[0].goodsAppRecordId)">参与活动</div>
																<div class="activity-btn" v-else @click="activityOption(0,value.activity[0].goodsAppRecordId)">参与活动</div>
															</div>
															<div v-else-if="value.activity[0].activityJoinStatus == 1|| value.activity[0].activityJoinStatus == 3" class="activity-btn" @click="activityOption(2,value.activity[0].goodsAppRecordId)">退出活动</div>
															<div v-else-if="value.activity[0].activityJoinStatus == 2" class="activity-btn"  @click="activityOption(1, value.activity[0].goodsAppRecordId)">参与活动</div>
														</div>
														<!-- <div class="font-color-green cursor-pointer shelves-to-detail td-div-marBot" @click="pushItem(value.shelvesVo[0].goodsAppRecordId)" v-if="selectItem[index].shelvesProduct[index1].status == '1'">推送</div>
														<div class="font-color-red cursor-pointer td-div-marBot"  v-else-if="selectItem[index].shelvesProduct[index1].status == '2'"></div>
														<div class="font-color-orange cursor-pointer td-div-marBot"  v-else-if="selectItem[index].shelvesProduct[index1].status == '3'" @click="pushItem(value.shelvesVo[1].goodsAppRecordId)">更新推送</div>
														<div class="td-div-marBot"  v-else-if="selectItem[index].shelvesProduct[index1].status == '4'" @click="pushItem(value.shelvesVo[1].goodsAppRecordId)">
															<div v-if="value.shelvesVo.length == 2" class="font-color-orange cursor-pointer">重新推送</div>
															<div class="font-color-red cursor-pointer" v-else>已失效</div>
														</div> -->



														<div class="font-color-green cursor-pointer shelves-to-detail td-div-marBot" @click="pushItem(value.shelvesVo[0].goodsAppRecordId)" v-if="selectItem[index].shelvesProduct[index1].status0 == '0'">推送</div>
														<div class="font-color-orange cursor-pointer td-div-marBot"  v-else-if="selectItem[index].shelvesProduct[index1].status1 == '6'||selectItem[index].shelvesProduct[index1].status1 == '7'" @click="pushItem(value.shelvesVo[1].goodsAppRecordId)">更新推送</div>
														

													</div>
												</td>
												<td class="shelves-table-item-img">
													<div class="shelves-table-item-imgwrap">
														<router-link tag="a" target="_blank" :to="{name: 'Detail', query: {goodsId: item.goodsId}}">
															<img v-bind:src="imgAddress + value.imagePath" @error="error(1)"/>
														</router-link>
														<!-- <div class="shixiao" v-if=" selectItem[index].shelvesProduct[index1].isUnEffect == true"></div> -->
													</div>
													<div class="activity-status" v-if="value.activity.length != 0" :class="{'weicanyu': value.activity[0].activityJoinStatus == 1|| value.activity[0].activityJoinStatus == 3}" @mouseenter="showMask(index, index1)" @mouseleave="hideMask(index, index1)">
														<div class="activity-infor" v-show="selectItem[index].shelvesProduct[index1].isShow">
															<div>活动时间：</div>
															<div>{{(value.activity[0].beginTime).substring(0,19)}} - {{(value.activity[0].endTime).substring(0,19)}}</div>
															<div>{{value.activity[0].notice}}</div>
															<div>不含税结算价：¥{{value.activity[0].settlementPrice/100}}</div>
															<div>含税结算价：¥{{value.activity[0].taxSettlementPrice/100}}</div>
															<div>总库存数：{{value.activity[0].inventoryNum}}</div>
														</div>
													</div>
													<div class="text-align-left td-div-marBot">{{value.specName}}</div>
													<div class="text-align-left">SKU：<span>{{value.productId}}</span></div>	
												</td>
												<td>
													<div class="td-div-marBot" v-for="product in value.shelvesVo">¥{{product.salePrice/100}}</div>
												</td>
												<td>
													<div v-for="product in value.shelvesVo">
														<div class="font-color-orange td-div-marBot" v-if="product.hasTax == 1">¥{{product.taxSettlementPrice/100}} <span class="goods-freight"> （+{{product.freight/100}})</span></div>
														<div class="font-color-orange td-div-marBot" v-else>¥{{product.settlementPrice/100}}<span class="goods-freight"> （+{{product.freight/100}})</span></div>
													</div>
												</td>
												<td>
													<div v-for="product in value.shelvesVo">
														<div class="font-color-orange td-div-marBot" v-if="product.hasTax == 0">{{product.availableNum}}</div>
														<div class="font-color-orange td-div-marBot" v-else>{{product.availableTaxNum}}</div>
													</div>
												</td>
												<td>
													<div v-for="product in value.shelvesVo">
														<div class="font-color-orange td-div-marBot" v-if="product.hasTax == 1">含税</div>
														<div class="font-color-orange td-div-marBot" v-else>不含税</div>
													</div>
												</td>
												<td>
													<div v-for="product in value.shelvesVo">
														<div class="font-color-orange td-div-marBot">{{(product.profitMargin * 100).toFixed(2)}}%</div>
													</div>
												</td>
												<td>
													<div>
														<div class="td-div-marBot">
															<span v-if="selectItem[index].shelvesProduct[index1].status0 =='3'">实时价格线</span>
															
														</div>
														<div class="font-color-green cursor-pointer td-div-marBot"  v-if="selectItem[index].shelvesProduct[index1].status0 == '0'">未推送更新</div>										
														<div class="font-color-green cursor-pointer td-div-marBot"  v-if="selectItem[index].shelvesProduct[index1].status0 == '4'||selectItem[index].shelvesProduct[index1].status0 == '7'">生效中</div>
														<div class="font-color-red cursor-pointer td-div-marBot"  v-if="selectItem[index].shelvesProduct[index1].status0 == '5'">断货</div>
														<div class="font-color-red cursor-pointer td-div-marBot"  v-if="selectItem[index].shelvesProduct[index1].status0 == '6'">涨价失效</div>
														
														
													</div>

													<div v-if="selectItem[index].shelvesProduct[index1].status1 !=='' ">
														<div>
															<span v-if="selectItem[index].shelvesProduct[index1].status1 == '0'" class="td-div-marBot">未推送更新</span>
															<span v-if="selectItem[index].shelvesProduct[index1].status1 =='3'" class="td-div-marBot">实时价格线</span>
														</div>										
														<div class="font-color-green cursor-pointer td-div-marBot"  v-if="selectItem[index].shelvesProduct[index1].status1 == '4'||selectItem[index].shelvesProduct[index1].status1 == '7'">生效中</div>
														<div class="font-color-red cursor-pointer td-div-marBot"  v-if="selectItem[index].shelvesProduct[index1].status1 == '5'">断货</div>
														<div class="font-color-red cursor-pointer td-div-marBot"  v-if="selectItem[index].shelvesProduct[index1].status1 == '6'">涨价失效</div>
														
														
													</div>
												</td>
											</tr>
										</tbody>
									</table>
								</div>
							
								<div class="block" v-if="!isShowImg">
									<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :current-page.sync="condition.pageNum" :total="goodsCount" :page-size="10"></el-pagination>
								</div>
							</div>
							<!-- 商品货架  end -->
							<!-- 回收站货架  start -->
							<div class="recycle-bin-shelves" v-show="!isShow">
								<div class="shelves-filter-wrap">
									<span class="shelves-input-item">
										<label>品牌名称：</label>
										<span>
											<input type="text" placeholder="请输入品牌名称" v-model="binFilterObj.brandName" />
										</span>
									</span>
									<span class="shelves-input-item">
										<label>商品名称：</label>
										<span>
											<input type="text" placeholder="请输入商品名称" v-model="binFilterObj.goodsName"/>
										</span>
									</span>
									<span class="shelves-input-item delete-goods-time">
										<label>删除时间：</label>
										<span>
											<el-date-picker
										      v-model="binFilterObj.deltime"
										      type="daterange"
										      placeholder="选择日期范围">
										    </el-date-picker>
										</span>
									</span>
									<span class="shelves-input-item">
										<!-- <label>二级分类：</label>
										<span class="classify-query">
											  <el-select v-model="binFilterObj.categoryTwoName" clearable placeholder="请输入货品编号" size="small">
											    <el-option
											      v-for="item in resTwoCatagory"
											      :key="item.value"
											      :label="item.label"
											      :value="item.label">
											    </el-option>
											  </el-select>
										</span> -->
										<label>二级分类：</label>
										<span>
											<input type="text" placeholder="请输入二级分类" v-model="binFilterObj.categoryTwoName"/>
										</span>

									</span>
									<span class="shelves-input-item">
										<!-- <label>三级分类：</label>
										<span class="classify-query">
											  <el-select v-model="binFilterObj.categoryThreeName" clearable placeholder="请输入货品编号" size="small">
											    <el-option
											      v-for="item in resThreeCatagory"
											      :key="item.value"
											      :label="item.label"
											      :value="item.label">
											    </el-option>
											  </el-select>
										</span> -->
										<label>三级分类：</label>
										<span>
											<input type="text" placeholder="请输入三级级分类" v-model="binFilterObj.categoryThreeName"/>
										</span>
									</span>
									<span>
										<span class="shelves-filter-btn-default shelves-filter" @click="binFilter(0)">筛选</span>
										<span class="shelves-filter-btn-default shelves-cancel" @click="clearbinFilterObj">取消</span>
									</span>
								</div>
								<div>
									<div class="noData" v-if="isShowbinImg">
										<img src="../assets/img/erro@2x.png">
										<p>暂未发现任何商品</p>
									</div>
									<table class="shelves-table" v-if="!isShowbinImg">
										<thead>
											<tr>
												<th>主图</th>
												<th width="500px">商品名称</th>
												<th>品牌名</th>
												<th>删除时间</th>
												<th>操作</th>
											</tr>
										</thead>
										<tbody>
										
											<tr v-for="item in bingoodsList">
												<td class="goods-img">
													<img :src="item.goodsImage">
													
												</td>
												<td class="goods-name" style="padding-left:50px;text-align:left;">
													<b style="text-align:center">电商</b>
													<span>{{item.goodsName}}</span>
												</td>
												<td>
													<span>{{item.brandName}}</span>
												</td>
												<td>
													<span>{{item.createTime}}</span>
												</td>
												<td class="operate-button">
													<router-link :to="{name: 'Detail', query: {goodsId: item.goodsId}}">
														<span>重新加入货架</span>
													</router-link>

													
												</td>
											</tr>

										</tbody>
									</table>
								</div>
								<div class="block" v-if="!isShowbinImg">
									<el-pagination layout="prev, pager, next" @current-change="handlebinCurrentChange" :current-page.sync="binFilterObj.pageNum" :total="binGoodsCount" :page-size="10"></el-pagination>
								</div>
							</div>
							<!-- 回收站货架  end -->

					</div>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
	import headerTop from '../components/Header'
	import store from '../store/index.js'
	import {myShelves,shelvesStatistics,pushNeedSend,recordCollect,send,batchAddCollect, activityOption, imgAddress} from '../config/interface.js'
	import {toast, imageError} from '../util/tool.js'
	import {fetch} from '../config/fetch.js'
	import router from '../router/index.js'

	export default {
		data(){
			return {
				pickerOptions2: {
		          	shortcuts: [{
			            text: '最近一周',
			            onClick(picker) {
			              const end = new Date();
			              const start = new Date();
			              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
			              picker.$emit('pick', [start, end]);
			            }
		          	}, {
			            text: '最近一个月',
			            onClick(picker) {
			              const end = new Date();
			              const start = new Date();
			              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
			              picker.$emit('pick', [start, end]);
			            }
		          	}, {
			            text: '最近三个月',
			            onClick(picker) {
			              const end = new Date();
			              const start = new Date();
			              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
			              picker.$emit('pick', [start, end]);
			            }
		          	}]
		        },
		        
				condition: {
					brandName: '',
					goodsName: '',
					productId: '',
					pushStatus:0,
					userId: store.state.userId,
					pageSize: 10,
					pageNum:1,
					categoryTwoName:'',
					categoryThreeName:''
				},    
				binFilterObj:{
					appId:localStorage.getItem("appId"),
					brandName:'',
					deltime:'',
					categoryThreeName:'',
					categoryTwoName:'',
					goodsName:'',
					pageSize: 10,
					pageNum: 1
				}, //回收站筛选对象
				kindNumber:{
					betterPrice:0,
					noInventory:0,
					normalSales:0,
					riseFailure:0,
					collect:0,
					noSend:0,
					all:0
				},  //每种类商品的数量
				searchWordArr:[],
				goodsList: {},
				bingoodsList:[],    //回收站商品列表
				selectAll: {},
				selectItem: {},
				isSelect: false,
				isShowImg:false,      //当数据为空时  表示是否显示图片（非回收站的商品）
				isShowbinImg:false,   //当数据为空时  表示是否显示图片（回收站的商品）
				goodAppRecordIds: {},
				bingoodsIds:[],    //存放回收站商品id
				imgAddress: imgAddress,
				goodsCount: 0,       //货架商品的数量
				binGoodsCount:0, //回收站商品的数量
				pageCount: '',
				sendUpdateGoods: false,
				sendUpdateGoodsDetail: false,
				sendUpdateSalePrice: false,
				defaultOpen: ['1'],      //侧边栏默认展开
				defaultActive:'1-0',  //默认选中第一个
				isShow:true,         //是否展示货架右边内容
				
			}
		},
		components: {
			headerTop
		},
		mounted(){
			this.kindgoodsCount();
			this.init();
			this.binFilter();
			
		},
		methods: {
			//左边侧边栏选择事件
			setStatus(val){
				
				if(val=='1-6'){
					this.isShow=false;

				}else{
					this.isShow=true;
					this.condition.pageNum=1;
					if(val=='1-0'){
						this.condition.pushStatus=0;
					}else if(val=='1-1'){
						this.condition.pushStatus=1;
						
					}else if(val=='1-2'){
						this.condition.pushStatus=2;
					}else if(val=='1-3'){
						this.condition.pushStatus=3;
					}else if(val=='1-4'){
						this.condition.pushStatus=4;
					}else{
						this.condition.pushStatus=5;
					}
					this.clearCondition();
					this.init();
				}
			},
			error(num){
				imageError(num, event);
			},
			
			//货架商品列表的筛选
			init(){
				var data = this.condition;
				var url = myShelves;
				fetch(url, data)
				.then(res => {
				  if(res.code==10000){
						this.goodsList = res.data.goods;
						this.goodsCount = res.data.goodsCount;
						if(this.goodsList.length>0){
							this.isShowImg=false;
						}else{
							this.isShowImg=true;
						}

						var arr = [];
						for(var i = 0; i < this.goodsList.length; i++){
							var opt = {
								id: i,
								isSelect: false
							};
							var shelvesProduct = [];
							for(var j = 0; j < this.goodsList[i].shelvesProduct.length; j++){								
								var obj = {
									id: j,
									isSelect: true,
									isChecked: false,
									goodsAppRecordId: '',
									goodsId:'',
									status0: '',
									status1:'',
									isShow: false
								};
								var item = this.goodsList[i].shelvesProduct[j];
								
										if(item.shelvesVo[0].position == 2&&item.shelvesVo[0].lineStatus == 2&&item.shelvesVo.length==1){
											obj.status0 = '0';// (状态未推送更新 操作显示推送)
										}else if(item.shelvesVo[0].position == 2&&item.shelvesVo[0].lineStatus == 1&&item.shelvesVo.length==1){
											obj.status0 = '1';// (状态断货)
										}else if(item.shelvesVo[0].position == 2&&item.shelvesVo[0].lineStatus == 5&&item.shelvesVo.length==1){
											obj.status0 = '2';// (状态无库存)
										}else if(item.shelvesVo[0].position == 2&&item.shelvesVo.length==2){
										obj.status0 = '3';// (状态显示实时价格线)
									    }else if(item.shelvesVo[0].position == 1&&item.shelvesVo[0].lineStatus == 0){
												obj.status0='4'; //正常零售（状态显示生效中）
										}else if(item.shelvesVo[0].position == 1&&(item.shelvesVo[0].lineStatus == 1||item.shelvesVo[0].lineStatus == 5)){
										 	obj.status0='5'; //商品已下架 无库存 （状态显示断货）
									    }else if(item.shelvesVo[0].position == 1&&(item.shelvesVo[0].lineStatus == 3||item.shelvesVo[0].lineStatus == 4)){
										 	obj.status0='6'; //涨价失效 （状态显示涨价失效  操作显示更新推送）
										}else if(item.shelvesVo[0].position == 1&&item.shelvesVo[0].lineStatus==6){  	
										   obj.status0='7'; //有更优价格 （状态显示生效中  操作显示更新推送）
										}
									
									
									obj.goodsId=item.shelvesVo[0].goodsId;
									obj.goodsAppRecordId = item.shelvesVo[0].goodsAppRecordId;
								
								if(item.shelvesVo.length>1){
										if(item.shelvesVo[1].position == 2){
											obj.status1 = '3';//第一次推送(状态显示实时价格线)
										}else if(item.shelvesVo[1].position == 1&&item.shelvesVo[1].lineStatus == 0){
											obj.status1='4'; //正常零售（状态显示生效中）
										}else if(item.shelvesVo[1].position == 1&&(item.shelvesVo[1].lineStatus == 1||item.shelvesVo[0].lineStatus == 5)){
											obj.status1='5'; //商品已下架 无库存 （状态显示断货）
										}else if(item.shelvesVo[1].position == 1&&(item.shelvesVo[1].lineStatus == 3||item.shelvesVo[1].lineStatus == 4)){
											obj.status1='6'; //涨价失效 （状态显示涨价失效）
										}else if(item.shelvesVo[1].position == 1&&item.shelvesVo[1].lineStatus == 6){
											obj.status1='7'; //有更优价格 （状态显示生效中  操作显示更新推送）
										}
									}

								if(item.shelvesVo.length == 1){
									// 四期
									// if(item.shelvesVo[0].position == 2&&item.shelvesVo[0].lineStatus ==5){
									// 	obj.status = '1';//第一次推送
									// }else if(item.shelvesVo[0].position == 1&&(item.shelvesVo[0].lineStatus == 1 || item.shelvesVo[0].lineStatus == 3)){
									// 	obj.status = '2'
									// }else if(item.shelvesVo[0].position == 1&&(item.shelvesVo[0].lineStatus == 2 || item.shelvesVo[0].lineStatus == 4)){
									// 	obj.status = '4'
									// }
									// obj.goodsAppRecordId = item.shelvesVo[0].goodsAppRecordId;
									// 五期
									
								}else{
									//四期
									// if(item.shelvesVo[1].hasTax == 0){
									// 	if((item.shelvesVo[1].lineStatus == 1 || item.shelvesVo[1].lineStatus == 3) && item.shelvesVo[0].hasTax == item.shelvesVo[1].hasTax && item.shelvesVo[0].settlementPrice == item.shelvesVo[1].settlementPrice){
									// 		obj.status = '2';//不推送
									// 	}else if((item.shelvesVo[1].lineStatus == 1 || item.shelvesVo[1].lineStatus == 3) && (item.shelvesVo[0].hasTax != item.shelvesVo[1].hasTax ||item.shelvesVo[0].settlementPrice != item.shelvesVo[1].settlementPrice)){
									// 		obj.status = '3';//更新推送
									// 	}else{
									// 		obj.status = '4';//重新推送
									// 	}
									// }else{
									// 	if((item.shelvesVo[1].lineStatus == 1 || item.shelvesVo[1].lineStatus == 3) && item.shelvesVo[0].hasTax == item.shelvesVo[1].hasTax && item.shelvesVo[0].taxSettlementPrice == item.shelvesVo[1].taxSettlementPrice){
									// 		obj.status = '2';//不推送
									// 	}else if((item.shelvesVo[1].lineStatus == 1 || item.shelvesVo[1].lineStatus == 3) && (item.shelvesVo[0].hasTax != item.shelvesVo[1].hasTax ||item.shelvesVo[0].taxSettlementPrice != item.shelvesVo[1].taxSettlementPrice)){
									// 		obj.status = '3';//更新推送
									// 	}else{
									// 		obj.status = '4';//重新推送
									// 	}
									// }
									// obj.goodsAppRecordId = item.shelvesVo[1].goodsAppRecordId;

									//五期
									
								}
								
								shelvesProduct.push(obj);
							}
							opt.shelvesProduct = shelvesProduct;
							arr.push(opt);
						}
						this.selectItem = arr;
					}else{
						toast(res.message, 2, false);
					}
					
				})
			},
			//分类
			// shelvesCategory(){
			// 	var data={};
			// 	data.appId=localStorage.getItem("appId");
			// 	data.userId=store.state.userId;
			// 	var url=shelvesCategory;
			// 	fetch(url,data)
			// 	.then(res=>{
			// 		if(res.code==10000){
			// 			var resTwoCatagory=[];
			// 			for(var i=0;i<res.data.resTwoCatagory.length;i++){
			// 				var obj={};
			// 				obj.value=i;
			// 				obj.label=res.data.resTwoCatagory[i];
			// 				resTwoCatagory.push(obj)
			// 			}  
					
			// 			this.resTwoCatagory=resTwoCatagory;

			// 			var resThreeCatagory=[];
			// 			for(var i=0;i<res.data.resThreeCatagory.length;i++){
			// 				var obj={};
			// 				obj.value=i;
			// 				obj.label=res.data.resThreeCatagory[i];
			// 				resThreeCatagory.push(obj)
			// 			}  
			// 			this.resThreeCatagory=resThreeCatagory;
			// 		}else{
			// 			toast(res.message, 2, false);
			// 		}
					
				
					
			// 	})

			// },
			//得到每个种类的商品数量
			kindgoodsCount(){
				var data={};
				data.appId=localStorage.getItem("appId");
				data.userId=store.state.userId;
				
				var url=shelvesStatistics
				fetch(url,data)
				.then(res => {
					if(res.code==10000){
						this.kindNumber.noSend=res.data.noSend;
						this.kindNumber.betterPrice=res.data.betterPrice;      //更优价格
						this.kindNumber.noInventory=res.data.noInventory;      //断货
						this.kindNumber.normalSales=res.data.normalSales;      //正常生效
						this.kindNumber.riseFailure=res.data.riseFailure;      //货源已涨价
						this.kindNumber.collect=res.data.collect;         //回收站
						this.binGoodsCount=res.data.collect;
						this.kindNumber.all=this.kindNumber.noSend+this.kindNumber.betterPrice+this.kindNumber.noInventory+this.kindNumber.normalSales+this.kindNumber.riseFailure+this.kindNumber.collect;
					}else{
						toast(res.message, 2, false);
					}
					

				})

			},
			//回收站的筛选出来的商品 ||回收站的商品列表
			binFilter(type){
					if(type==0){
						this.binFilterObj.pageNum=1;
					}
					if(this.binFilterObj.deltime!==''){
						var startTime=new Date(this.binFilterObj.deltime[0]); 
						var endTime=new Date(this.binFilterObj.deltime[1]);
						startTime=startTime.getFullYear()+'-'+(startTime.getMonth()+1)+'-'+startTime.getDate();
						endTime=endTime.getFullYear()+'-'+(endTime.getMonth()+1)+'-'+endTime.getDate();
					}
					
					
					var data={};
					data.appId=this.binFilterObj.appId;
					data.brandName=this.binFilterObj.brandName;
					data.categoryTwoName=this.binFilterObj.categoryTwoName;
					data.categoryThreeName=this.binFilterObj.categoryThreeName;
					data.goodsName=this.binFilterObj.goodsName;
					data.startTime=startTime;
					data.endTime=endTime;
					data.pageNum=this.binFilterObj.pageNum;
					data.pageSize=10;
					data.userId=store.state.userId;
					
					var url=recordCollect;
					console.log(data)
					fetch(url,data)
					.then(res=>{
						if(res.code==10000){
							this.binGoodsCount=res.data.count;
							if(res.data.resultGoods.length>0){
								this.isShowbinImg=false;
								this.bingoodsList=res.data.resultGoods;
								console.log(res.data.resultGoods)
							}else{
								this.isShowbinImg=true;
								this.bingoodsList=res.data.resultGoods;
								
							}
						}else{
							toast(res.message, 2, false);
						}
						
					})
			},
			selectItemAll(id){
				this.selectItem[id].isSelect = !this.selectItem[id].isSelect;
				for(var i = 0; i < this.selectItem[id].shelvesProduct.length; i++){
					this.selectItem[id].shelvesProduct[i].isChecked = this.selectItem[id].isSelect;				
				}
			},
			selectItemFuc: function(index, indexone){
				this.selectItem[index].shelvesProduct[indexone].isChecked = !this.selectItem[index].shelvesProduct[indexone].isChecked;

			},
			allSelect(){
				this.isSelect = !this.isSelect;
				for(var i = 0; i < this.selectItem.length; i++){
					this.selectItem[i].isSelect = this.isSelect;
					for(var j = 0; j < this.selectItem[i].shelvesProduct.length; j++){
						this.selectItem[i].shelvesProduct[j].isChecked = this.isSelect;														
					}
				}
				console.log(this.selectItem)
			},
			//批量推送
			push(){
				var data = {
						goodsAppRecordList: this.goodAppRecordIds,
						sendUpdateGoods: 0,
						sendUpdateGoodsDetail: 0,
						sendUpdateSalePrice: 0,
						userId: this.condition.userId
					};
					var arr = [];
				for(var i = 0; i < this.selectItem.length; i++){
					
					for(var j = 0; j < this.selectItem[i].shelvesProduct.length; j++){
						if(this.selectItem[i].shelvesProduct[j].isChecked == true && this.selectItem[i].shelvesProduct[j].isSelect == true){
							var opt = {
								goodsAppRecordId: this.selectItem[i].shelvesProduct[j].goodsAppRecordId
							}
							arr.push(opt);
							console.log(111);
							console.log(arr)
						}
					}


					if(this.sendUpdateGoods == true){
						data.sendUpdateGoods = 1;
					}else{
						data.sendUpdateGoods = 0;
					}

					if(this.sendUpdateGoodsDetail == true){
						data.sendUpdateGoodsDetail = 1;
					}else{
						data.sendUpdateGoodsDetail = 0;
					}

					if(this.sendUpdateSalePrice == true){
						data.sendUpdateSalePrice = 1;
					}else{
						data.sendUpdateSalePrice = 0;
					}

				
				}
				this.goodAppRecordIds = arr;
					console.log(arr);
					console.log(this.goodAppRecordIds)
					data.goodsAppRecordList=this.goodAppRecordIds;
				console.log(this.goodAppRecordIds)
				
				if(this.goodAppRecordIds.length != 0){
					var url = send;
					fetch(url, data)
					.then(res => {
						if(res.code == 10000){
							var str = res.message;
			                toast(str, 1, false);
			                this.isSelect = false;
							this.init();
						}else{
							var str = res.message;
			                toast(str, 2, false);
							}
						});
					}
				
			},
			//批量放入回收站
			putInbin(){
				var arr = [];
				
				for(var i = 0; i < this.selectItem.length; i++){
					
					for(var j = 0; j < this.selectItem[i].shelvesProduct.length; j++){
						if(this.selectItem[i].shelvesProduct[j].isChecked == true && this.selectItem[i].shelvesProduct[j].isSelect == true){
							
							arr.push(this.selectItem[i].shelvesProduct[j].goodsId);
						}
					}
					this.bingoodsIds = arr;
					
				}

				if(this.bingoodsIds.length>0){
				        const h = this.$createElement;
				        this.$msgbox({
				          title: '',
				          message:h('div',{style:'text-align:center'},[
				          		h('p',{style:'color:#494949;font-size:22px'},'你真的要删除所选商品吗?'),
				          		h('span',{style:'color:#494949;font-size:14px'},'放入回收站后,对应的商品将无法正常下单')
				          	]),
				          showCancelButton: true,
				          confirmButtonText: '确定',
				          cancelButtonText: '再想想',
				          confirmButtonClass:'confirmButtonBtn',
				          cancelButtonClass:'cancelButtonBtn',
				          beforeClose: (action, instance, done) => {
				            if (action === 'confirm') {
				            	
				            	this.confirmAddcollect();
				            	done();
				              
				            } else {
				              done();
				            }
				          }
				        }).then(action => {
				         
				        });
				    }else{
				    	toast('请先选择商品', 3, false);
				    }			
			},
			//确定放入回收站
			confirmAddcollect(){
					
					
							var data = {
							goodsIds: this.bingoodsIds,
							userId: this.condition.userId,
							appId:localStorage.getItem("appId")
						}
						
						if(this.bingoodsIds.length != 0){
							var url = batchAddCollect;
							fetch(url, data)
							.then(res =>{
								if(res.code == 10000){
									var str = res.message;
				                    toast(str, 1, false);
				                    this.isSelect = false;
									this.init();
									this.kindgoodsCount();
									this.binFilter();
								}else{
									var str = res.message;
				                    toast(str, 2, false);
								}
							});
						
						}
					
				
			},
			//批量推送未生效信息
			pushIneffective(){
					var data={};
					data.appId=localStorage.getItem("appId");
					data.userId=store.state.userId;
					var url=pushNeedSend;
					console.log(data)
					fetch(url,data)
					.then(res=>{
						if(res.code == 10000){
									var str = res.message;
				                    toast(str, 1, false);
								}else{
									var str = res.message;
				                    toast(str, 2, false);
							}
					})
			},
			pushItem(id){
				var arr = [];
				var opt = {
					goodsAppRecordId: id
				};
				arr.push(opt);
				this.goodAppRecordIds = arr;
				var data = {
					goodsAppRecordList: this.goodAppRecordIds,
					sendUpdateGoods: 0,
					sendUpdateGoodsDetail: 0,
					sendUpdateSalePrice: 0,
					userId: this.condition.userId
				};
				console.log(data)
				if(this.sendUpdateGoods == true){
					data.sendUpdateGoods = 1;
				}else{
					data.sendUpdateGoods = 0;
				}

				if(this.sendUpdateGoodsDetail == true){
					data.sendUpdateGoodsDetail = 1;
				}else{
					data.sendUpdateGoodsDetail = 0;
				}

				if(this.sendUpdateSalePrice == true){
					data.sendUpdateSalePrice = 1;
				}else{
					data.sendUpdateSalePrice = 0;
				}

				var url = send;
				fetch(url, data)
				.then(res => {
					if(res.code == 10000){
						var str = res.message;
	                    toast(str, 1, false);
						this.init();
					}else{
						var str = res.message;
	                    toast(str, 2, false);
					}
				});
			},
			clearCondition(){
				this.condition.brandName = '';
				this.condition.goodsName = '';
				this.condition.productId = '';
				this.condition.categoryTwoName='';
				this.condition.categoryThreeName='';
				this.condition.pageNum=1;
				this.init();
			},
			clearbinFilterObj(){
				this.binFilterObj.brandName = '';
				this.binFilterObj.goodsName = '';
				this.binFilterObj.deltime='';
				this.binFilterObj.categoryTwoName='';
				this.binFilterObj.categoryThreeName='';
				this.binFilterObj.pageNum=1;
				this.binFilter();
			},
			handleCurrentChange(val) {
		        this.condition.pageNum = val;
		        this.isSelect = false
		        this.init();
		    },
		    //商品回收站当前页面改变时触发的事件
		    handlebinCurrentChange(val){
		    	this.binFilterObj.pageNum=val;
		    	this.binFilter();
		    },
		    showMask(a,b){
		    	this.selectItem[a].shelvesProduct[b].isShow = true;
		    },
		    hideMask(a,b){
		    	this.selectItem[a].shelvesProduct[b].isShow = false;
		    },
		    activityOption(num, id){
		    	if(num == 0){
		    		var str = '请先推送！';
	                toast(str, 2, false);
	                return;
		    	}
		    	const data = {
		    		actOption: num,
		    		goodsAppRecordId: id,
		    		userId: this.condition.userId
		    	};

		    	const url = activityOption;

		    	fetch(url, data)
		    	.then(res => {
		    		if(res.code == 10000){
		    			var str = '操作成功！';
	                    toast(str, 1, false);
	                    this.init();
		    		}else{
		    			var str = '操作失败！';
	                    toast(str, 2, false);
		    		}
		    	})
		    }
		}
	}
</script>
<style>

</style>